#! /bin/sh
### BEGIN INIT INFO
# Provides:          amonsys
# Short-Description: Asterisk Peers Monitoring System
# Description:       Real time sip peers monitoring of Asterisk based in Asterisk Manager
### END INIT INFO

# Author: Acta Desing & Creation <actadc@actadc.com.br>

AMONSYS_USER=amonsys
AMONSYS_CONFIGDIR=/etc/amonsys/

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Real time sip peers monitoring of Asterisk based in Asterisk Manager"
NAME=amonsys
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="-confdir $AMONSYS_CONFIGDIR -uid `id -u $AMONSYS_USER` "
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh


#
# Function that starts the daemon/service
#
do_start()
{
	start-stop-daemon --start -b --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start -b --quiet --pidfile $PIDFILE --exec $DAEMON -- \
		$DAEMON_ARGS \
		|| return 2
}

do_reload() {
	start-stop-daemon --stop -b --signal 1 --quiet --pidfile $PIDFILE --name $NAME
	return 0
}

case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	killall -9 amonsys
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop}" >&2
	exit 3
	;;
esac

:
